
package com.snail.mobile.sim.oss.dictionaryinfo.web.action;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;

import com.sungrid.seine.oss.framework.service.BaseManager;
import com.sungrid.seine.oss.framework.util.PageList;
import com.sungrid.seine.oss.framework.web.action.BaseDispatchAction;

import com.snail.mobile.sim.oss.dictionaryinfo.model.TblDictionaryInfoOss;
import com.snail.mobile.sim.oss.dictionaryinfo.service.TblDictionaryInfoOssManager;
import com.snail.mobile.sim.oss.dictionaryinfo.web.form.TblDictionaryInfoOssForm;

/**
 * Action class to handle CRUD on a TblDictionaryInfoOss object
 *
 * @struts.action name="tblDictionaryInfoOssForm" path="/business/dictionaryinfo/tblDictionaryInfoOsss" scope="request"
 *  validate="false" parameter="method"
 * @struts.action name="tblDictionaryInfoOssForm" path="/business/dictionaryinfo/deleteTblDictionaryInfoOss" scope="request"
 *  validate="false" parameter="method"
  * @struts.action name="tblDictionaryInfoOssForm" path="/business/dictionaryinfo/editTblDictionaryInfoOss" scope="request"
 *  validate="false" parameter="method"
 * @struts.action name="tblDictionaryInfoOssForm" path="/business/dictionaryinfo/saveTblDictionaryInfoOss" scope="request"
 *  validate="true" parameter="method" input="edit"

 * @struts.action-forward name="edit" path="tblDictionaryInfoOss.form"
 * @struts.action-forward name="search" path="tblDictionaryInfoOss.list"
 * @struts.action-forward name="list" path="tblDictionaryInfoOsss.do"  redirect="true"
 */
public final class TblDictionaryInfoOssAction extends BaseDispatchAction
{

    public ActionForward cancelled(ActionMapping mapping, ActionForm form,
                                HttpServletRequest request,
                                HttpServletResponse response)
    throws Exception
    {
        return mapping.findForward("list");
    }

    public ActionForward delete(ActionMapping mapping, ActionForm form,
                                HttpServletRequest request,
                                HttpServletResponse response)
    throws Exception
    {
        if (log.isDebugEnabled())
        {
            log.debug("Entering 'delete' method");
        }

        ActionMessages messages = new ActionMessages();
        TblDictionaryInfoOssForm tblDictionaryInfoOssForm = (TblDictionaryInfoOssForm) form;

        // Exceptions are caught by ActionExceptionHandler
        TblDictionaryInfoOssManager mgr = (TblDictionaryInfoOssManager) getBean("tblDictionaryInfoOssManager");
        mgr.removeTblDictionaryInfoOss(tblDictionaryInfoOssForm.getNid());

        messages.add(ActionMessages.GLOBAL_MESSAGE,
                     new ActionMessage("tblDictionaryInfoOss.deleted"));

        // save messages in session, so they'll survive the redirect
        saveMessages(request.getSession(), messages);

        return mapping.findForward("list");
    }

    public ActionForward edit(ActionMapping mapping, ActionForm form,
                              HttpServletRequest request,
                              HttpServletResponse response)
    throws Exception
    {
        if (log.isDebugEnabled())
        {
            log.debug("Entering 'edit' method");
        }

        TblDictionaryInfoOssForm tblDictionaryInfoOssForm = (TblDictionaryInfoOssForm) form;

        // if an id is passed in, look up the user - otherwise
        // don't do anything - user is doing an add
        if (tblDictionaryInfoOssForm.getNid() != null) {
            TblDictionaryInfoOssManager mgr = (TblDictionaryInfoOssManager) getBean("tblDictionaryInfoOssManager");
            TblDictionaryInfoOss tblDictionaryInfoOss = mgr.getTblDictionaryInfoOss(tblDictionaryInfoOssForm.getNid());
            tblDictionaryInfoOssForm = (TblDictionaryInfoOssForm) convert(tblDictionaryInfoOss);
            updateFormBean(mapping, request, tblDictionaryInfoOssForm);
        }

        return mapping.findForward("edit");
    }

    public ActionForward save(ActionMapping mapping, ActionForm form,
                              HttpServletRequest request,
                              HttpServletResponse response)
    throws Exception
    {
        if (log.isDebugEnabled())
        {
            log.debug("Entering 'save' method");
        }

        // Extract attributes and parameters we will need
        ActionMessages messages = new ActionMessages();
        TblDictionaryInfoOssForm tblDictionaryInfoOssForm = (TblDictionaryInfoOssForm) form;
        boolean isNew = ("".equals(tblDictionaryInfoOssForm.getNid()) || tblDictionaryInfoOssForm.getNid() == null);

        TblDictionaryInfoOssManager mgr = (TblDictionaryInfoOssManager) getBean("tblDictionaryInfoOssManager");

        TblDictionaryInfoOss tblDictionaryInfoOss = null;

        // add success messages
        if (isNew)
        {
            tblDictionaryInfoOss = (TblDictionaryInfoOss) convert(tblDictionaryInfoOssForm);

            messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("tblDictionaryInfoOss.added"));

            // save messages in session to survive a redirect
            saveMessages(request.getSession(), messages);
        } else
        {
            tblDictionaryInfoOss = mgr.getTblDictionaryInfoOss(tblDictionaryInfoOssForm.getNid());
            copyProperties(tblDictionaryInfoOss, tblDictionaryInfoOssForm);

            messages.add(ActionMessages.GLOBAL_MESSAGE,
                         new ActionMessage("tblDictionaryInfoOss.updated"));
            saveMessages(request, messages);
        }

        mgr.saveTblDictionaryInfoOss(tblDictionaryInfoOss);

        return mapping.findForward("list");
    }

    public ActionForward search(ActionMapping mapping, ActionForm form,
                                HttpServletRequest request,
                                HttpServletResponse response)
    throws Exception
    {
        if (log.isDebugEnabled())
        {
            log.debug("Entering 'search' method");
        }

        // TblDictionaryInfoOssForm tblDictionaryInfoOssForm = (TblDictionaryInfoOssForm) form;
        // TblDictionaryInfoOss tblDictionaryInfoOss = (TblDictionaryInfoOss) convert(tblDictionaryInfoOssForm);

		DetachedCriteria detachedCriteria = DetachedCriteria.forClass(TblDictionaryInfoOss.class);

		List orders = new ArrayList();

        orders.add(Order.desc("nid"));

        // TblDictionaryInfoOssManager mgr = (TblDictionaryInfoOssManager) getBean("tblDictionaryInfoOssManager");
        BaseManager mgr = (BaseManager)getBean("baseManager");

        PageList pageList = mgr.findPageList(detachedCriteria, getPage(request), orders);

        setPageList(request, pageList);

        return mapping.findForward("search");
    }

    public ActionForward unspecified(ActionMapping mapping, ActionForm form,
                                     HttpServletRequest request,
                                     HttpServletResponse response)
    throws Exception
    {
        return search(mapping, form, request, response);
    }
}